Column

Chart A

Column

Chart B

Chart C

---
title: "Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source : embed
---

```{r setup, include=FALSE}
library(tidyverse)
library("p8105.datasets")
library(plotly)
library(flexdashboard)
```

```{r codes, include=FALSE}
data("instacart") 
instacart %>% 
  count(aisle) %>% 
  arrange(desc(n)) %>% 
  filter(n>10000) %>% 
  mutate(
    aisle = factor(aisle),
    aisle = fct_reorder(aisle,n)
    )

instacart %>%
  filter(aisle == "milk") %>% 
  group_by(product_name) %>% 
  count(product_name) %>% 
  arrange(desc(n)) 
```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart A

```{r}
instacart %>% 
  filter(aisle %in% c("fresh fruits"), product_name == "Strawberries") %>%
  mutate(text_label = str_c("Order_dow: ", order_dow, "\nOrder_number: ", order_number, "\norder_hour_of_day: ", order_hour_of_day)) %>% 
  plot_ly(
    x = ~order_hour_of_day, y = ~order_number, color = ~order_hour_of_day, text = ~text_label, alpha = .5, type = "scatter", mode = "markers", colors = "viridis") %>% 
  layout(
  title = "Strawberries order_hour_of_day and order_number scatter plot"
  )

```

Column {data-width=650}
-----------------------------------------------------------------------

### Chart B

```{r}
instacart %>%
  filter(product_name %in%  c("Organic Whole Milk", "2% Reduced Fat Milk", "Organic Reduced Fat 2% Milk")) %>% 
  plot_ly(
    x = ~product_name, y = ~order_number, color = ~product_name,
    alpha = .5, type = "box", mode = "markers"
    ) %>% 
  layout(
    title = "Top 3 most popular milk's order_number distribution"
  )
```

### Chart C

```{r}
instacart %>% 
  count(aisle) %>% 
  filter(n>10000) %>% 
  mutate(
    aisle = factor(aisle),
    aisle = fct_reorder(aisle,n)
  ) %>% 
  plot_ly(x = ~aisle, y = ~n, color = ~aisle,
          type = "bar", colors = "viridis") %>% 
    layout(
      xaxis = list(title = FALSE),
    title = "Aisles more than 10000 ordered"
  )
# rmarkdown::render("dashboard.Rmd", output_format = "flexdashboard::flex_dashboard")
```